var people = {
    name: "Tom",
    sayHello: function () {
        console.log("Hello," + this.name)
    }
}
people.sayHello()

class People {
    name: string;

    constructor(name: string) {
        this.name = name
    }

    sayHello() {
        console.log("Hello," + this.name)
    }
}

var p = new People("小王")
p.sayHello()

class Teacher extends People {
    teach() {
        console.log(this.name + ",进行教学。")
    }

    sayHello() {
        super.sayHello();
        console.log("override teacher")
    }
}

class Student extends People {
    study() {
        console.log(this.name + ",进行学习。")
    }

    sayHello() {
        super.sayHello();
        console.log("override student")
    }
}

var t = new Teacher("小明")
t.teach()
var s = new Student("小红")
s.study()
t.sayHello()
s.sayHello()

class Animal {
    protected name: string;
    private age: number;

    constructor(name: string, age: number) {
        this.name = name;
        this.age = age;
    }

    run() {
        console.log(this.name + " is running")
    }
}

class Cat extends Animal {
    constructor(name: string, age: number) {
        super(name, age);
    }

    run() {
        console.log(this.name + " is running")
    }
}

var cat = new Cat("小花", 2)
cat.run()

class Circle {
    public radius: number; // 使用 public 关键字
    static readonly pi: number = 3.14;

    constructor(radius: number) {
        this.radius = radius;
    }

    area(): number {
        return Circle.pi * this.radius * this.radius;
    }

    // set radius(value: number) {
    //     if (value < 0) {
    //         throw new Error("半径不能小于0"); // 使用双引号包围字符串
    //     }
    //     this.radius = value; // 设置 radius 属性的值
    // }
}


var c = new Circle(10)
console.log(c.area())

var data1 = {
    name: "小明",
    age: 12,
}
var data2 = {
    ...data1
}
console.log(data1)
console.log(data2)
data2.name = "小红"
console.log(data2.name)
console.log(data2.age)

abstract class Goods {
    abstract price(): number;
}

class Bread extends Goods {
    price() {
        return 10
    }
}

var bread = new Bread()
console.log(bread.price())

interface Tips {
    label: string
    color?: string

    [propName: string]: number | string
}

function descLog(t: Tips) {
    console.log(t.label)
}

var circle: Tips = {
    label: "圆形"
}
descLog(circle)
var rectangle: Tips = {
    label: "矩形",
    width: 10,
    height: 20
}

interface JArray {
    [index: number]: string
}

interface JDictonary {
    [key: string]: string
}

let arr: JArray = ["a", "b", "c"]
let map: JDictonary = {
    "key1": "value1",
    "key2": "value2"
}
console.log(arr)
console.log(map)

interface Shape {
    area(): number
}

interface ColorInterface {
    color: string
}

interface CircleInterface extends Shape, ColorInterface {
    radius: number
}

var circleImpl: CircleInterface = {
    radius: 10,
    color: "red",
    area() {
        return Math.PI * this.radius * this.radius
    }
}
console.log(circleImpl.area())

var num=10

var arr10=[1,'hello',false,null];

interface Color2{
    color:string
}
class Blue implements Color2{
    color='Blue'
}
class Green implements Color2{
    color='Green'
}
var colors:Color2[]=[new Blue(),new Green()]


